<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Ruby Summary: Ruby Study Notes - Best Ruby Guide, Ruby Tutorial</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="Ruby Study Notes - Best Ruby Guide, Ruby Tutorial" />
<meta name="keywords" content="free ruby programming guide,ruby guide,free ruby programming course,best ruby guide,ruby tutorials,ruby tutorial,learn ruby,ruby,ruby on rails,ruby rails,ruby learning,ruby tutoring,learning ruby,ruby programming,ruby on rails development,ruby training" />
<meta name="Distribution" content="Global" />
<meta name="author" content="Satish Talim / Original design: Erwin Aligam - ealigam@gmail.com" />
<meta name="copyright" content="Satish Talim 2007 and beyond..." />
<meta name="verify-v1" content="rFu86se+IkbtF+bH8mgJBKwU5HnKaSd8Ghw9umXQOkM=" />
<meta name="robots" content="index,follow" />
<meta http-equiv="Expires" content="0" />
<meta name="revisit-after" content="1 days" />
<link rel="stylesheet" href="/images/NewOrange.css" type="text/css" />
<link rel="icon" type="image/ico" href="/images/favicon.ico" />
<!-- Google +1 button code -->
<link rel="canonical" href="/satishtalim/ruby_summary4.html" />
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<!-- Google Analytics code -->
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-59044-10']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
<!-- Google Analytics code ends -->
</head>

<body>
<!-- wrap starts here -->
<div id="wrap">

    <div id="header">

        <h1 id="logo">Ruby<span class="orange">Learning.github.io</span></h1>
        <h2 id="slogan">Helping Ruby Programmers become Awesome!</h2>

    </div>

    <div id="menu">
        <ul>
            <li><a href="/" title="Home page for rubylearning.github.io">Home</a></li>
            <li><a href="/satishtalim/tutorial.html" title="Get started Learning Ruby here...">Tutorial</a></li>
            <li><a href="/download/downloads.html" title="Download this tutorial as an eBook">Downloads</a></li>
            <li><a href="/other/testimonials.html" title="People around the world who benefited from this site">Testimonials</a></li>
            <li><a href="/other/certification.html" title="Get certified in Ruby">Certification</a></li>
            <li><a href="/satishtalim/ruby_guide.html" title="Ruby Guide, Mentor">Mentor</a></li>
            <li><a href="https://blog.rubylearning.github.io/" title="Ruby blog of Learning Ruby site">Blog</a></li>
            <li><a href="/satishtalim/tutorial.html" title="Online Ruby Course">Online Course</a></li>
            <li><a href="http://ruby-challenge.rubylearning.github.io/" title="Ruby Programming Challenge for Newbies">Challenge</a></li>
            <li><a href="/satishtalim/about.html" title="Information about Satish Talim">About</a></li>
        </ul>
    </div>

    <!-- content-wrap starts here -->
    <div id="content-wrap">


            <div id="main">
                <!-- google_ad_section_start -->
                <div id="main-inner"><a name="TemplateInfo"></a>
                <h1>Ruby Summary</h1>

                <p class="post-footer align-right">
                  <strong>
                    <a href="/satishtalim/read_write_files.html">&lt;Read/Write Files | </a>
                    <a href="/satishtalim/tutorial.html">TOC | </a>
                    <a href="/satishtalim/ruby_regular_expressions.html">Regular Expressions&gt;</a>
                  </strong>
                </p>

                <ol>
                  <li>An <strong>Array</strong> is just a list of items in order. Every slot in the list acts like a variable: you can see what object a particular slot points to, and you can make it point to a different object. You can make an array by using square brackets.</li>
                  <li>Arrays are indexed by integers and the index starts from 0.</li>
                  <li>A trailing comma in an array declaration is ignored.</li>
                  <li>You can access an array beyond its boundary limits; it will return <strong>nil</strong>.</li>
                  <li>We can add more elements to an existing array.</li>
                  <li>Refer to the <strong>Array</strong> documentation for a list of methods.</li>
                  <li>The method <strong>each</strong> of an Array calls a <em>block</em> once for each element in Array, passing that element as a parameter.</li>
                  <li>The variable inside the "goalposts" (i.e. | |) refers to each item in the array as it goes through the loop. You can give this any name you want.</li>
                  <li>Sequences have a start point, an end point, and a way to produce successive values in the sequence. In Ruby, these sequences are created using the ".." and "..." range operators and are called Range.</li>
                  <li>The two dot form creates an inclusive range, and the three-dot form creates a range that excludes the specified high value.</li>
                  <li>In Ruby, the sequence 1..100000 is held as a <strong>Range</strong> object containing references to two <strong>Fixnum</strong> objects.</li>
                  <li>The <strong>.to_a</strong> method converts a <strong>Range</strong> to an <strong>Array</strong>.</li>
                  <li>Another use of the versatile range is as an interval test: seeing if some value falls within the interval represented by the range. We do this using ===, the case equality operator.</li>
                  <li>Ranges are not limited to integers or numbers. The beginning and end of a range may be any Ruby object.</li>
                  <li>A symbol looks like a variable name but it's prefixed with a colon.</li>
                  <li>You can think of :id as meaning the name of the variable id, and plain id as meaning the value of the variable.</li>
                  <li>Symbols are useful because a given symbol name refers to the same object throughout a Ruby program.</li>
                  <li>Symbols can be considered constants without values.</li>
                  <li>Symbols are more efficient than strings. Two strings with the same contents are two different objects, but for any given name there is only one <strong>Symbol</strong> object. This can save both time and memory.</li>
                  <li>When do we use a string versus a symbol?<ul><li>If the contents (the sequence of characters) of the object are important, use a string.</li><li>If the identity of the object is important, use a symbol.</li></ul></li>
                  <li>A <strong>Symbol</strong> object is created by prefixing an operator, string, variable, constant, method, class, module name with a colon.</li>
                  <li>If Fred is a constant in one context, a method in another, and a class in a third, the Symbol :Fred will be the same object in all three contexts.</li>
                  <li>Hashes are similar to arrays in that they are indexed collection of object references. However, while you index arrays with integers, you can index a hash with objects of any types: strings, regular expressions, and so on.</li>
                  <li>When you store a value in a hash, you actually supply two objects - the index (normally called the key) and the value.</li>
                  <li><strong>nil</strong> is returned when an attempt is made to access keys that do not exist in the hash.</li>
                  <li>The method to get a randomly chosen number in Ruby is <strong>rand</strong>.</li>
                  <li>If you call <strong>rand</strong>, you'll get a float greater than or equal to 0.0 and less than 1.0. If you give it an integer parameter (by calling rand(5) ), you will get an integer value greater than or equal to 0 and less than 5.</li>
                  <li>The <strong>File.open</strong> method can open a file in different modes like 'r' Read-only, starts at beginning of file (default); 'r+' Read/Write, starts at beginning of file; 'w' Write-only, truncates existing file to zero length or creates a new file for writing.</li>
                  <li><strong>File.open</strong> opens a new <strong>File</strong> if there is no associated block. If the optional block is given, it will be passed file as an argument, and the file will automatically be closed when the block terminates.</li>
                  <li>Always close a file that you open. In the case of a file open for writing, this is very important and can actually prevent lost data.</li>
                  <li>The <strong>seek</strong> method of class <strong>IO</strong>, seeks to a given offset an Integer (first parameter of method) in the stream according to the value of second parameter in the method. The second parameter can be <strong>IO::SEEK_CUR</strong> - Seeks to first integer number parameter plus current position; <strong>IO::SEEK_END</strong> - Seeks to first integer number parameter plus end of stream (you probably want a negative value for first integer number parameter); <strong>IO::SEEK_SET</strong> - Seeks to the absolute location given by first integer number parameter.</li>
                </ol>

                <p style="background-color: #FAFAFA; padding: 5px; margin-top: 20px; font-size: 65%;"><strong>Note</strong>: The Ruby Logo is Copyright (c) 2006, Yukihiro Matsumoto. I have made extensive references to information, related to Ruby, available in the public domain (wikis and the blogs, articles of various <span style="font-weight: bold;" title="Click Gurus on the menu above">Ruby Gurus</span>), my acknowledgment and thanks to all of them. Much of the material on <a href="/">rubylearning.github.io</a> and in the course at <a href="http://rubylearning.org/">rubylearning.org</a> is drawn <strong>primarily</strong> from the <strong>Programming Ruby book</strong>, available from <a href="http://pragprog.com/book/ruby3/programming-ruby-1-9-2-0">The Pragmatic Bookshelf</a>.</p>

                <!-- google_ad_section_end -->
                <p class="post-footer align-right">
                  <strong>
                    <a href="/satishtalim/read_write_files.html">&lt;Read/Write Files | </a>
                    <a href="/satishtalim/tutorial.html">TOC | </a>
                    <a href="/satishtalim/ruby_regular_expressions.html">Regular Expressions&gt;</a>
                  </strong>
                </p>

            </div>
            <!-- main inner ends here -->
        </div>

            <div id="rightbar">

            </div>

    <!-- content-wrap ends here -->
    </div>

<!-- wrap ends here -->
</div>

<!-- footer starts here -->
<div id="footer">
    <!-- CHANGE THE FOOTER -->
    <p> &copy; 2006-2021 <strong>rubylearning.github.io A Ruby Tutorial</strong>&nbsp;&nbsp;Page Updated: 5th Jan. 2021 | Design: <a href="mailto:ealigam@gmail.com">Erwin Aligam</a> | Valid: <a href="http://validator.w3.org/check/referer">XHTML</a> | <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="/">Home</a> | <a href="/privacy.html">Privacy</a> | <a href="/sitemap.html">Sitemap</a> </p>
</div>
<!-- footer ends here -->

</body>
</html>
